/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "MUSIC_GENRE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicGenre.findAll", query = "SELECT m FROM MusicGenre m"),
    @NamedQuery(name = "MusicGenre.findByIdMusicGenre", query = "SELECT m FROM MusicGenre m WHERE m.idMusicGenre = :idMusicGenre"),
    @NamedQuery(name = "MusicGenre.findByNameMusicGenre", query = "SELECT m FROM MusicGenre m WHERE m.nameMusicGenre = :nameMusicGenre")})
public class MusicGenre implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_MUSIC_GENRE")
    private Integer idMusicGenre;
    @Basic(optional = false)
    @Column(name = "NAME_MUSIC_GENRE")
    private String nameMusicGenre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idMusicGenre")
    private Collection<Artist> artistCollection;

    public MusicGenre() {
    }

    public MusicGenre(Integer idMusicGenre) {
        this.idMusicGenre = idMusicGenre;
    }

    public MusicGenre(Integer idMusicGenre, String nameMusicGenre) {
        this.idMusicGenre = idMusicGenre;
        this.nameMusicGenre = nameMusicGenre;
    }

    public Integer getIdMusicGenre() {
        return idMusicGenre;
    }

    public void setIdMusicGenre(Integer idMusicGenre) {
        Integer oldIdMusicGenre = this.idMusicGenre;
        this.idMusicGenre = idMusicGenre;
        changeSupport.firePropertyChange("idMusicGenre", oldIdMusicGenre, idMusicGenre);
    }

    public String getNameMusicGenre() {
        return nameMusicGenre;
    }

    public void setNameMusicGenre(String nameMusicGenre) {
        String oldNameMusicGenre = this.nameMusicGenre;
        this.nameMusicGenre = nameMusicGenre;
        changeSupport.firePropertyChange("nameMusicGenre", oldNameMusicGenre, nameMusicGenre);
    }

    @XmlTransient
    public Collection<Artist> getArtistCollection() {
        return artistCollection;
    }

    public void setArtistCollection(Collection<Artist> artistCollection) {
        this.artistCollection = artistCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMusicGenre != null ? idMusicGenre.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicGenre)) {
            return false;
        }
        MusicGenre other = (MusicGenre) object;
        if ((this.idMusicGenre == null && other.idMusicGenre != null) || (this.idMusicGenre != null && !this.idMusicGenre.equals(other.idMusicGenre))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.MusicGenre[ idMusicGenre=" + idMusicGenre + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
